<div id="uploadPack" class="modal fade" data-backdrop="static" role="dialog" tabindex="-1">
	<input class="In" type="hidden" id="versionIdhidden" /> <input
		class="In" type="hidden" id="platform" />
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal"
			aria-hidden="true">×</button>
		<h3 id="myModalLabel" class="text-center">安装包上传</h3>
	</div>
	<div class="modal-body" style="height: 100px">
		<div class="text-right pad-st-b5">
			<input class="In" type="hidden" id="sourcetype" />
			<table class="text-center">
				<tr>
					<td class="bd_sr" width="10%"></td>
					<td class="bd_sr"><div id="bundleUploadContainer"></div></td>
				</tr>
			</table>
		</div>
	</div>
	<div class="modal-footer">
		<button class="btn btn-common btn-small tls" data-dismiss="modal"
			aria-hidden="true">关闭</button>
		<button class="btn btn-primary btn-small tls" id="myPackbtn">保存</button>
	</div>
</div>

<script type="text/javascript">
	var packageSubfix = {
		"ios" : "ipa",
		"android" : "apk"
	}

	/**
	 *  显示myCert前需要把id为platform的输入框值填上
	 */
	$(function() {

		$('#uploadPack').on('hidden', function() {
			$("#bundleUploadContainer").empty();
		});

		$('#uploadPack').on('shown', function() {
			var platform = $("#platform").val();
			var uploader = buildPlupload({
				id : "bundleUploadContainer",
				elmName : "bundle",
				filters : [ {
					title : "安装包",
					extensions : packageSubfix[platform]
				} ],
				tips : "上传的应用安装包不正确,请上传" + packageSubfix[platform] + "文件",
				targetUrl : "{{ctx}}/mam/attachment/upload",
				defaultVal : "",
				btnName : "上传安装包"
			});
		});

	})

	var popover = function(inputId, content) {
		var options = {
			placement : "bottom",
			content : content
		};
		$('#' + inputId).attr("data-toggle", "popover");
		$('#' + inputId).popover(options);
		$('#' + inputId).popover('show');
	}

	//添加版本页面保存
	function save() {

		var bundle = $('#bundleUploadContainerInput').val();
		if (bundle === "") {
			bootbox.alert("请上传安装包");
		} else {
			$("#bundle").val(bundle);
			$('#uploadPack').modal("hide");
			$('#status').val("3");
			$("#statusinfo").text("已激活");
		}
	}

	//详情页面上传安装包
	function updateBundle(versionId) {
		var bundle = $('#bundleUploadContainerInput').val();
		if (bundle === "") {
			bootbox.alert("请上传安装包");
		} else {
			$.ajax({
				async : true,
				type : "POST",
				url : "{{ctx}}/mam/pkg/bundle/" + versionId + "?bundle="
						+ bundle,
				dataType : 'json',
				success : function(data, textStatus) {
					if (data.result == "success") {
						$('#uploadPack').modal("hide");
						$('#status').val("3");
						bootbox.alert("保存成功", function() {
							window.location.reload();
						});
					} else {
						bootbox.alert("保存失败，请稍后再试！");
					}
				},
				error : function(data, status, e) {
					bootbox.alert("系统繁忙，请稍后再试！");
				}
			});
		}
	}
</script>